package Top200;

/**
 * @author zhangmin
 * @create 2022-02-24 9:30
 */
public class uniquePathsWithObstacles63 {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int m=obstacleGrid.length,n=obstacleGrid[0].length;
        int[][] dp=new int[m][n];
        dp[0][0]=obstacleGrid[0][0]==1?0:1;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (i==0&&j==0) continue;
                if (obstacleGrid[i][j]==1) continue;
                if (i==0){
                    dp[i][j]=dp[i][j-1];
                    continue;
                }else if (j==0){
                    dp[i][j]=dp[i-1][j];
                    continue;
                }
                dp[i][j]=dp[i-1][j]+dp[i][j-1];
            }
        }
        return dp[m-1][n-1];
    }
}
